/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：绘制有限状态机的窗口
* CreateTime：2020-07-07 17:22:08
* Version：1.0
* Modify Recorder：
*************************************************/

using TinyToolKit;
using TinyToolKit.FSM;
using UnityEditor;

namespace TinyToolKitEditor
{
    public class DrawWindowFSM : DrawWindowBase
    {
        private TFsmManager _fsmManager;

        protected override void DrawInternalMainGUI()
        {
            TinyToolWindowUtil.DrawDefaultEditorGUI(); 
            
            if (EditorApplication.isPlaying == false || TinyTool.Instance.HasManager<TFsmManager>() == false) return;
            if (_fsmManager == null) _fsmManager = TinyTool.Instance.GetManager<TFsmManager>();

            FsmSystemBase[] fsmsDic = _fsmManager.GetAllFsms();
            if (fsmsDic.Length > 0)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                TinyToolWindowUtil.DrawTableHead("名称", "状态");
                foreach (FsmSystemBase fsmItem in fsmsDic)
                {
                    string stateName = fsmItem.CurrentStateName;
                    bool isRunning = fsmItem.IsRunning;
                    string time = fsmItem.CurrentStateTime.ToString("0.0");
                    string info = $"当前状态：{stateName}，正在运行：{isRunning}，持续时间：{time}";
                    EditorGUILayout.LabelField(fsmItem.Name, info);
                }
                TinyToolWindowUtil.DrawTableTail("总计：", _fsmManager.FsmCount.ToString());
                EditorGUILayout.EndVertical();
            }
        }
    }
}
